# -*- coding: utf-8 -*-
# @Author  : gaoyu
# @Time    : 2024/2/6 10:37 PM
# @Function:

class Evapotranspiration:
    """
    流域蒸散发
    """

    def __init__(self):
        self.E = None
        self.ED = None
        self.EL = None
        self.EU = None
        self.EP = None
        self.EM = None
        self.P = None
        self.WL = None
        self.WU = None
        self.C = None
        self.LM = None
        self.KC = None

    def SetParmameter(self, parameter):
        """
        设置参数
        Args:
            parameter:

        Returns:

        """
        self.KC = parameter.m_KC
        self.LM = parameter.m_LM
        self.C = parameter.m_C

    def SetState(self, state):
        self.WU = state.m_WU
        self.WL = state.m_WL
        self.P = state.m_P
        self.EM = state.m_EM

    def calculate(self):
        # 三层蒸散发计算
        self.EP = float(self.KC) * float(self.EM)  # 计算流域蒸发能力
        if float(self.P) + float(self.WU) >= float(self.EP):
            self.EU = self.EP
            self.EL = 0
            self.ED = 0
        else:
            self.EU = self.P + self.WU
            if self.WL >= float(self.C) * float(self.LM):
                self.EL = (float(self.EP) - float(self.EU)) * float(self.WL) / float(self.LM)
                self.ED = 0
            else:
                if self.WL >= float(self.C) * (float(self.EP) - float(self.EU)):
                    self.EL = float(self.C) * (float(self.EP) - float(self.EU))
                    self.ED = 0
                else:
                    self.EL = self.WL
                    self.ED = float(self.C) * (float(self.EP) - float(self.EU)) - float(self.EL)
        # 计算总的蒸散发量
        self.E = self.EU + self.EL + self.ED

    def UpdateState(self, state):
        state.m_EP = self.EP
        state.m_E = self.E
        state.m_EU = self.EU
        state.m_EL = self.EL
        state.m_ED = self.ED
